package com.jwell.panprovider.model

import com.jwell.driverapp.tools.BaseSubscriber
import com.jwell.panprovider.application.App
import com.jwell.panprovider.contract.SearchContract
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * Created by 76577 on 2018/4/10.
 * 各种搜索
 */
class SearchModel : SearchContract.Model, BaseModel() {
    override fun getContractList(filter: String?, baseSubscriber: BaseSubscriber) {
        val map = mutableMapOf("filter" to filter)
        if (App.DEBUG) println("查询合同号" + map.toString())
        getApiStore().getContractList(map)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(baseSubscriber)
    }

    override fun getDriverList(filter: String?, baseSubscriber: BaseSubscriber) {
        val map = mutableMapOf("nameOrPhone" to filter)
        if (App.DEBUG) println("查询司机" + map.toString())
        getApiStore().getDriverList(map)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(baseSubscriber)
    }

    override fun appGetProList(filter: String?, baseSubscriber: BaseSubscriber) {
        val map = mutableMapOf("filter" to filter)
        if (App.DEBUG) println("查询产品列表" + map.toString())
        getApiStore().appGetProList(map)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(baseSubscriber)

    }

    override fun appGetUnitInformationList(filter: String?, baseSubscriber: BaseSubscriber) {
        val map = mutableMapOf("filter" to filter)
        if (App.DEBUG) println("查询收发货单位" + map.toString())
        getApiStore().appGetUnitInformationList(map)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(baseSubscriber)
    }

}